Page({
    data: {
        y_phb_list: [],
        y_phb_listLimit: 0,
        base: 10,
    },
    onLoad: function (options) {
        this.yys_index();
    },

    //获取医生的资料
    yys_index() {
        var timestamp = Date.parse(new Date());
        var that = this;
        //链接远程服务器
        swan.request({
            url: 'https://api.cndzys.com/index.php/yys_index', 
            method: 'GET',
            //dataType: 'json',
            data: { num: that.data.y_phb_listLimit },
            header: { 'content-type': 'application/json' },
            success: function (res) {
                that.setData({ data_user: res.data.data_user})

                console.log(res.data.array);
                var y_phb_arr = that.data.y_phb_list.concat(res.data.data_art)
                console.log(res.data.data_art.length);
                if (res.data.data_art.length > 10) {
                    that.setData({ error: 1 })
                }
                console.log(y_phb_arr);
                that.setData({
                    y_phb_list: y_phb_arr,
                })
            },
        });
    },
    //获取文章的资料
    yys_artlist() {
        var timestamp = Date.parse(new Date());
        var that = this;
        //链接远程服务器
        swan.request({
            url: 'https://api.cndzys.com/index.php/yys_artlist', 
            method: 'GET',
            data: { num: that.data.y_phb_listLimit },
            header: { 'content-type': 'application/json' },
            success: function (res) {
                console.log(res.data.array);
                var y_phb_arr = that.data.y_phb_list.concat(res.data.data_art)
                console.log(res.data.data_art.length);
                if (res.data.data_art.length > 10) {
                    that.setData({ error: 1 })
                }
                console.log(y_phb_arr);
                that.setData({
                    y_phb_list: y_phb_arr,
                })
            },
        });
    },

    onReachBottom: function () {
        console.log("我滑动到底部了");
        this.setData({
          requestStatus: true,
          y_phb_listLimit: this.data.y_phb_listLimit + this.data.base
        })
        this.yys_artlist();
    },

    
    qanda(e) { 
        swan.navigateTo({ url:'../qanda/qanda' });
        return;
    },

    search(e) {
        console.log(1);
    },

    //获取用户输入的简介
    infoInput: function (e) {
        var info = e.detail.value.replace(/\s+/g, '');
        if(!info){
            this.setData({error: '2',});
            setTimeout(function () {
            this.setData({
                error: ""
            })
            }.bind(this), 1500)
            return;
        }
        swan.navigateTo({ url:'../search/search?title='+info+'&type=arr'});
    },
    

    
    article(e) {
        console.log(2);
        let article = e.currentTarget.dataset.id;
        swan.navigateTo({
            url:'../article/article'
        });
        return;
    },
    articledetail(event) {
        var art_id = event.currentTarget.id
        swan.navigateTo({ url:'../articledetail/articledetail?art_id=' + art_id  });
    },

    
    doctor(event) {
        var doc_id = event.currentTarget.id
        swan.navigateTo({ url:'../doctor/doctor?doc_id=' + doc_id  });
    },
    upper: e => {
        console.log('upper', e);
    },
    lower: e => {
        console.log('lower', e);
    },
    myscroll: e => {
        console.log('scroll', e);
    }
});